//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace OpenLS.Spreadsheet
{
#if DEBUG
    public static class StackTraceHelper
    {
        static Dictionary<string,int> _data = new Dictionary<string, int>(); 
        public static void Trace()
        {
            string s = (new StackTrace()).ToString();
            if (_data.ContainsKey(s))
            {
                int i = _data[s];
                i++;
                _data[s] = i;
            }
            else
            {
                _data[s] = 0;
            }
        }

        public static void Output()
        {
            List<KeyValuePair<string, int>> pairs = new List<KeyValuePair<string, int>>(_data);
            pairs.Sort((p1, p2) => p1.Value.CompareTo(p2.Value));
            foreach (var item in pairs)
            {
                Debug.WriteLine( "_______________________________________________________--");
                Debug.WriteLine(item.Value);
                Debug.WriteLine(item.Key);
            }
        }
    }
#endif
    internal static class EventHandlerHelper
    {
        public static EventHandler<TEventArgs> MakeWeak<TEventArgs>(EventHandler<TEventArgs> eventHandler,
            OpenLS.Chart.WeakEventHelper.UnregisterCallback<TEventArgs> unregister)
            where TEventArgs : EventArgs
        {
#if DEBUG
            StackTraceHelper.Trace();
#endif
            return OpenLS.Chart.WeakEventHelper.MakeWeak<TEventArgs>(eventHandler, unregister);
        }
    }
}
